package cn.edu.ldu.modules.controller;

import cn.edu.ldu.http.rqtUtils;
import cn.edu.ldu.modules.entity.GroupChatEntity;
import cn.edu.ldu.util.Consts;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.List;

public class GroupChatController extends BaseController {

    public static List<GroupChatEntity> getGroupChats(Long userId, String token) throws Exception {

        JSONObject jsonObject = rqtUtils.httpclientGet(new StringBuffer(Consts.getGroupChats).append("/").append(userId), token);
        if(jsonObject.getString("msg").equals("success")){
            return JSONObject.parseArray(jsonObject.getString("groupChat"), GroupChatEntity.class);
        }
        return null;
    }

    public static void createGroupChat(GroupChatEntity groupChatEntity){

        String jsonString = JSONObject.toJSONString(groupChatEntity);

    }

    public static GroupChatEntity getGroupChat(Long groupId, String token) throws Exception {

        JSONObject jsonObject = rqtUtils.httpclientGet(new StringBuffer(Consts.getGroupChat).append("/").append(groupId), token);
        if(jsonObject.getString("msg").equals("success")){
            return JSONObject.parseObject(jsonObject.getString("groupChat"), GroupChatEntity.class);
        }
        return null;

    }


}
